package de.itagile.hypersphere

import de.itagile.hypersphere.mock.MapxmiAdapterStub
class EjbTemplateProcessesEntityWithFieldsTest extends GroovyTestCase {
	
	def xml = 
		'''
			<entity id="BOOK">
				<ejb-name>Book</ejb-name>
				<local>ejbs.BookLocal</local>
				<cmpfield id="0">
					<fieldname>id</fieldname>
				</cmpfield>
				<cmpfield id="1">
					<fieldname>title</fieldname>
				</cmpfield>
			</entity>
		'''
	def entity = new XmlParser().parseText(xml)
	def entityTemplate = new EjbTemplate(null,
			new MapxmiAdapterStub(),
			new EntityTemplateFactory())
				.getEntityTemplate(entity)
			
	void testSetsFirstFieldsOnEntityTemplate() {
		assertEquals("0", entityTemplate.fields[0].id)
		assertEquals("id", entityTemplate.fields[0].name)
		assertEquals("java.lang.Integer", entityTemplate.fields[0].type)
		assertEquals("ID_COLUMN", entityTemplate.fields[0].column)
	}
		
	void testSetsSecondFieldsOnEntityTemplate() {
		assertEquals("1", entityTemplate.fields[1].id)
		assertEquals("title", entityTemplate.fields[1].name)
		assertEquals("java.lang.String", entityTemplate.fields[1].type)
		assertEquals("TITLE_COLUMN", entityTemplate.fields[1].column)
	}
}